package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2024-12-03
 */

@Api(tags = "车辆模块")
@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息,vehicleQuery={}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息,vehicleSaveParam={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("deleteVehicle/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除车辆,id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{id}")
    public JsonResult unbindVehicle(@PathVariable Long id){
        log.debug("解绑车辆,id={}", id);
        vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geoId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geoId,@PathVariable Long vehicleId){
        log.debug("绑定车辆,geoId={},vehicleId={}", geoId, vehicleId);
        vehicleService.bindVehicle(geoId,vehicleId);
        return JsonResult.ok();
    }
}
